#include <stdio.h>

typedef struct 
{
    int numarator,numitor;
} rational;

rational adauga (rational a, rational b);
rational opus (rational r);
rational scadere (rational a, rational b);
rational produs (rational a, rational b);
rational invers (rational r);
rational cat (rational a, rational b);
int cmmdc (int a, int b);
rational simplifica (rational r);
void scrie(rational x);

rational adauga(rational a,rational b)
{
	rational c;
	c.numarator = a.numarator*b.numitor + b.numarator*a.numitor;
	c.numitor = a.numitor*b.numitor;
    c=simplifica(c);
	return c;
}

rational opus (rational r)
{
	rational c;
	c.numarator = -r.numarator;
	c.numitor = r.numitor;
    
	return c;
}

rational scadere (rational a,rational b)
{
	rational c,d;
	d=opus(b);
    c=adauga(a, d);    
    return c;
    
}

rational produs (rational a, rational b)
{
	rational c;
	c.numarator = a.numarator * b.numarator;
	c.numitor = a.numitor * b.numitor;
	return c;
}

rational invers (rational r)
{
	rational c;
	c.numarator = r.numitor;
	c.numitor = r.numarator;
    return c;
}

rational cat ( rational a, rational b)
{
	rational c,d;
	d = invers(b);
	c.numarator = a.numarator * d.numarator;
	c.numitor = a.numitor * d.numitor;
	return c;
}

int cmmdc (int a, int b)
{
	int c;
	while (b!=0)
	{
		c=a%b;
		a=b;
		b=c;
	}
	return a;
}

rational simplifica (rational r)
{
	rational c;
	int x;
	x=cmmdc(r.numarator,r.numitor);
	c.numarator = r.numarator / x;
	c.numitor = r.numitor / x;
	return c;
}
void scrie(rational x)
{
	printf("%d|%d\n",x.numarator,x.numitor);
}
int main()
{
	rational x,y,z;
	x.numarator = 12;
	x.numitor = 8;
	y.numarator = 9;
	y.numitor = 18;
	//scrie(x);
	//scrie(y);
	z=adauga(x,y);scrie(z);
	z=opus(x);scrie(z);
	z=scadere(x,y);scrie(z);
	z=produs(x,y);scrie(z);
	z=invers(x);scrie(z);
	z=cat (x,y);scrie(z);
	z=simplifica(x);scrie(z);
	return 0;
}
